#include "../source/server.hpp"
#define TIMEOUT 10
void OnClose(const PtrConnection& conn){
    DBG_LOG("CLOSE CONNECTION:%p", conn.get());
}
void OnConnected(const PtrConnection &conn) {
    DBG_LOG("NEW CONNECTION:%p", conn.get());
}
void OnMessage(const PtrConnection&conn,Buffer*buf){
    //设置给messagecallback相当于这里是业务处理函数
    //buf里面是接收缓冲区数据
    //这里的send就是把数据发到conn发送缓冲区
    //连接发送信息
    DBG_LOG("业务处理：%s", buf->ReadPosition());
    buf->MoveReadOffset(buf->ReadAbleSize());
    std::string str = "Hello World";
    conn->Send(str.c_str(), str.size());//这里得send还需要完善
    conn->Shutdown();
}
int main()
{
    TCP_Server server(8080);
    server.SetThreadCount(2);
    server.SetMessageCallback(OnMessage);
    server.SetConnectedCallback(OnConnected);
    server.SetClosedCallback(OnClose);
    server.EnableInactiveRelease(TIMEOUT);
    server.Start();
}